package com.aal.model;

import com.aal.business.CategoryManagementLocal;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

/**
 *
 * @author Quy
 * edited by Hoang
 */
public class CategoryManagement {
    CategoryManagementLocal categoryManagement = lookupCategoryManagementLocal();
    
    private int categoryID;
    
    private String categoryName;
   
    private String categoryDescription;
    
    private String hidden;

    public void setHidden(String hidden) {
        this.hidden = hidden;
    }
    
    public com.aal.entity.Category getCategory(){
        return categoryManagement.getCategory(categoryID);
    }
    
    public void setCategoryDescription(String categoryDescription) {
        this.categoryDescription = categoryDescription;
    }

    public void setCategoryID(int categoryID) {
        this.categoryID = categoryID;
    }

    public void setCategoryName(String categoryName) {
        this.categoryName = categoryName;
    }
    
    public boolean getCreateCategory(){
        return categoryManagement.createCategory(categoryName, categoryDescription);
    }
    public boolean getEditCategory(){
        return categoryManagement.editCategory(categoryName, categoryDescription);
    }
    public boolean getDeleteCategory(){
        return categoryManagement.deleteCategory(categoryName);
    }
    public List<com.aal.entity.Category> getViewAll(){
        return categoryManagement.viewAll();
    }
    public List<com.aal.entity.Category> getSearchCategory(){
        return categoryManagement.searchCategory(categoryName);
    }

    private CategoryManagementLocal lookupCategoryManagementLocal() {
        try {
            Context c = new InitialContext();
            return (CategoryManagementLocal) c.lookup("java:global/AAL/AAL-ejb/CategoryManagement!com.aal.business.CategoryManagementLocal");
        } catch (NamingException ne) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }
    
}
